﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TowerOfHanoi
{
    internal class Program
    {
        /// <summary>
        /// 汉诺塔的移动路径
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.WriteLine("请输入汉诺塔的层数");
            int Towernumber = Convert.ToInt32(Console.ReadLine());
            MovingOfOneStep(Towernumber, 'A', 'B', 'C');
            Console.ReadKey();   
        }

        /// <summary>
        /// 利用递归函数，可从结果逆推，
        /// </summary>
        public static void MovingOfOneStep(int Towernumber, char A, char B, char C)
        {
            //从Towernumber=input开始一直-1往前递归，直到Towernumber==1,写出第一步，然后返回去运行Towernumber==2
            //第一个盘的移动
            if (Towernumber == 1)
                Console.WriteLine($"将{Towernumber}号盘从{A}柱移到{C}柱");
            //剩下n-1层
            else
            {
                MovingOfOneStep(Towernumber - 1, A, C,B);
                Console.WriteLine($"将{Towernumber}号盘从{A}柱到{C}柱");
                MovingOfOneStep(Towernumber - 1, B, A,C);
            }   
        }
    }
}
